jQ(function(){
	//jQ("div.my_clips_menu a.sysmsg").addClass("sysmsgonit");
	jQ("#left_clip_list").empty();
	jQ("input.hminput").val(0);
	//analyzeUrl();
	
	initRightContent();
	jQ("#viewopt").dialog({
		modal: true,
		bgiframe: true,
		autoOpen: false,
		closeOnEscape:false,
		draggable:false,
		height:200,
		buttons: {
			
			"确定": function() {
				var opt=jQ("#viewopt");
				var triggerfun=opt.data("function");
				opt.trigger(triggerfun);
				opt.removeData("function");
				jQ("#viewopt_p").hide();
				jQ("#viewopt_img").show();
				//activeBtnOnDialog("viewopt",false);
				//jQ(this).dialog('close');
			},
			"取消": function() {
				var viewopt=jQ("#viewopt");
				var triggerfun=jQ("#viewopt").data("function");
				viewopt.unbind(triggerfun);
				viewopt.find("input.eventid").val("");
				viewopt.removeData("function");
				jQ(this).dialog('close');
			}
		},
		close: function() {
			jQ("#viewopt_p").show();
			jQ("#viewopt_img").hide();
		},
		open:function(){
		}
	});
	
	jQ("div.upscreen").click(function(){
		if(jQ(this).hasClass("onit")){
			jQ(this).removeClass("onit");
			jQ(this).parent("div.et_screen").find("div.src_all").hide();
		}else{
			jQ(this).addClass("onit");
			jQ(this).parent("div.et_screen").find("div.src_all").show();
		}
	});
	jQ("div.dwscreen").click(function(){
		if(jQ(this).hasClass("onit")){
			jQ(this).removeClass("onit");
			jQ(this).parent("div.et_screen").find("div.src_all").hide();
		}else{
			jQ(this).addClass("onit");
			jQ(this).parent("div.et_screen").find("div.src_all").show();
		}
	});	
	
	jQ("span.upgoto").click(function(){
		if(jQ(this).hasClass("onit")){
			jQ(this).removeClass("onit");
			jQ(this).parent("div.page").find("div.home_end").hide();
		}else{
			jQ(this).addClass("onit");
			jQ(this).parent("div.page").find("div.home_end").show();
		}
	});
	
	jQ("span.dwgoto").click(function(){
		if(jQ(this).hasClass("onit")){
			jQ(this).removeClass("onit");
			jQ(this).parent("div.page").find("div.home_end").hide();
		}else{
			jQ(this).addClass("onit");
			jQ(this).parent("div.page").find("div.home_end").show();
		}
	});
});

function analyzeUrl(){
	var href="";
	var paramStr=location.href;
	if(paramStr.indexOf("#")>0){
		href=paramStr.substring(paramStr.indexOf("#")+1);
    }
	if(href.length>0){
		jQ("div.samepage a").removeClass("onit");
		jQ("div.samepage a[mstype='"+href+"']").addClass("onit");
	}else{
		jQ("div.samepage a[mstype='all']").addClass("onit");
	}
	var currentpage=eval(getParameter("currentpage"));
	if(isNaN(currentpage)||currentpage==null){
		jQ("#mainpart_list_content").data("currentpage",0);
	}else{
		jQ("#mainpart_list_content").data("currentpage",currentpage);
	}
}




function formateDetailTime(daytime){
	var temp=new Date();
	temp.setTime(eval(daytime));
	return temp.pattern("yyyy年MM月dd日 HH:mm");
}

function formateTitleTime(daytime){
	var temp=new Date();
	temp.setTime(eval(daytime));
	return temp.pattern("yyyy年MM月dd日");
}

function getTypeName(eng){
	if(eng=='other'){
		return "其他";
	}else if(eng=='work'){
		return "工作";
	}else if(eng=='socal'){
		return "社交";
	}else if(eng=='sect'){
		return "私人";
	}
}
function loadMessage(type){
	jQ.ajax({
		type : "POST",
		url : "messageAjax!loadMessage.action",
		data : {
			type : type
		},
		success : function(data){
			jQ("#message_content div.outer").empty().hide();
			if(type=='request'){
				var requestslist=data.requests;
				if(requestslist.length==0){
					var html="<span class='empty'>目前没有好友请求</span>";
					jQ("#content-request").append(html).show();
				}else{
					var html="";
					for(var i=0;i<requestslist.length;i++){
						var requestobj=requestslist[i];
						html += "<div class='line'>";
						html += "<a class='first'></a>";
						html += "<span class='request' title='好友请求' requestuid=\""+requestobj.contactuid+"\"></span>";
						html += "<span class='content'>";
						html += "<img class='logo' width=50 height=50 src=\""+requestobj.biglogo+"\" title='"+requestobj.contactname+"'/>";
						html += "<p class='top'><span ><a href=\""+jQ("#ctxVal").val()+"/myclip/user.html?"+requestobj.contactuid+"\">"+requestobj.contactname+"</a></span></p>";
						html += "<p class='bottom'><span style=\"color:#999;\">想加您为好友</span></p>";
						html += "</span>";
						html += "<a class=\"ignore\"></a>";
						html += "<a class=\"agree\"></a>";
						html += "</div>";
					}
					html += "<div class='emptyline'></div>";
					jQ("#content-request").append(html).show();
					jQ("#content-request>div.line>a.ignore").click(request_ignore);
					jQ("#content-request>div.line>a.agree").click(request_agree);
				}
			}else if(type=='systemmsg'){
				var systemmsgslist=data.systemmsgs;
				if(systemmsgslist.length==0){
					var html="<span class='empty'>目前没有档期通知</span>";
					jQ("#content-systemmsg").append(html).show();
				}else{
					var html="";
					for(var i=0;i<systemmsgslist.length;i++){
						var systemmsgobj=systemmsgslist[i];
						var msgtype=systemmsgobj.msgtype; 
						var shareid=systemmsgobj.shareid;
						html += "<div class='line'>";
						html += "<a class='first'></a>";
						html += "<span class='systemmsg' title='档期通知' msgtype='"+msgtype+"' systemmsgid=\""+systemmsgobj.msgid+"\" eventid=\""+systemmsgobj.eventid+"\" shareid='"+shareid+"'></span>";
						html += "<span class='content'>";
						html += "<img class='logo' width=50 height=50 src=\""+systemmsgobj.frombiglogo+"\" title='"+systemmsgobj.fromuname+"'/>";
						html += "<p class='top'>";
						html += "<span ><a href=\""+jQ("#ctxVal").val()+"/myclip/user.html?"+systemmsgobj.fromuid+"\">"+systemmsgobj.fromuname+"</a></span>";
						html += "<span>";
						html += "在 "+formateDetailTime(systemmsgobj.msgtime);
						html += "</span>";
						html += "</p>";
						if(msgtype==1){
							html += "<p class='bottom'><span >取消了活动："+systemmsgobj.eventtitle+"</span></p>";
						}else if(msgtype==2){
							html += "<p class='bottom'><span >邀请您参加活动："+systemmsgobj.eventtitle+"</span></p>";
						}
						html += "</span>";
						html += "<a class=\"ignore\"></a>";
						html += "<a class=\"detail\"></a>";
						html += "</div>";
					}
					html += "<div class='emptyline'></div>";
					jQ("#content-systemmsg").append(html).show();
					jQ("#content-systemmsg>div.line>a.ignore").click(systemmsg_ignore);
					jQ("#content-systemmsg>div.line>a.detail").click(systemmsg_detail);
				}
			}else if(type=='comment'){
				var commentslist=data.comments;
				if(commentslist.length==0){
					var html="<span class='empty'>目前没有评论提示</span>";
					jQ("#content-comment").append(html).show();
				}else{
					var html="";
					for(var i=0;i<commentslist.length;i++){
						var commentobj=commentslist[i];
						var commenttype=commentobj.commenttype; 
						/*		NORMALTYPE=0
						*		INTERESTEVENTTYPE=1;
						*		CANCELINTERESTEVENTTYPE=2;
						*		CONFIRMEVENTTYPE=3;
						*		FORWARDEVENTTYPE=4;
						*		QUITEVENTTYPE=5;
						*/
						html += "<div class='line'>";
						html += "<a class='first'></a>";
						html += "<span class='comment' title='评论提示' noticeid=\""+commentobj.noticeid+"\" eventid='"+commentobj.eventid+"' shareid='"+commentobj.shareid+"'></span>";
						html += "<span class='content'>";
						html += "<img class='logo' width=50 height=50 src=\""+commentobj.biglogo+"\" title='"+commentobj.name+"'/>";
						html += "<p class='top'>";
						html += "<span ><a href=\""+jQ("#ctxVal").val()+"/myclip/user.html?"+commentobj.uid+"\">"+commentobj.name+"</a></span>";
						html += "<span>";
						html += "在 "+formateDetailTime(commentobj.commenttime);
						html += "</span>";
						html += "</p>";
						if(commenttype==0){
							html += "<p class='bottom'><span >评论了活动："+commentobj.title+"</span></p>";
						}else if(commenttype==1){
							html += "<p class='bottom'><span >对活动："+commentobj.title+"表示感兴趣</span></p>";
						}else if(commenttype==2){
							html += "<p class='bottom'><span >对活动："+commentobj.title+"取消了感兴趣</span></p>";
						}else if(commenttype==3){
							html += "<p class='bottom'><span >对活动："+commentobj.title+"进行了一拍即合操作</span></p>";
						}else if(commenttype==4){
							html += "<p class='bottom'><span >对活动："+commentobj.title+"进行了呼朋唤友操作</span></p>";
						}else if(commenttype==5){
							html += "<p class='bottom'><span >退出了活动："+commentobj.title+"</span></p>";
						}
						
						html += "</span>";
						html += "<a class=\"ignore\"></a>";
						html += "<a class=\"detail\"></a>";
						html += "</div>";
					}
					html += "<div class='emptyline'></div>";
					jQ("#content-comment").append(html).show();
					jQ("#content-comment>div.line>a.ignore").click(comment_ignore);
					jQ("#content-comment>div.line>a.detail").click(comment_detail);
				}
			}else if(type=='remind'){
				var remindslist=data.alertevents;
				if(remindslist.length==0){
					var html="<span class='empty'>目前没有档期提醒</span>";
					jQ("#content-remind").append(html).show();
				}else{
					var html="";
					for(var i=0;i<remindslist.length;i++){
						var remindobj=remindslist[i];
						html += "<div class='line'>";
						html += "<a class='first'></a>";
						html += "<span class='remind' title='档期提醒' eventid='"+remindobj.eventid+"'></span>";
						html += "<span class='content'>";
						html += "<img class='logo' width=50 height=50 src=\""+jQ("#ctxVal").val()+"/image/box_clipmessagelogo.jpg"+"\" title='档期提醒'/>";
						html += "<p class='top'><span ><a href=\"javascript:void(0);\">档期网</a></span>";
						html += "<span>";
						html += "在 "+formateDetailTime(remindobj.clocktime);
						html += "</span>";
						html += "</p>";
						html += "<p class='bottom'><span>提醒您活动："+remindobj.title+"</span></p>";
						html += "</span>";
						html += "<a class=\"ignore\"></a>";
						html += "<a class=\"agree\"></a>";
						html += "</div>";
					}
					html += "<div class='emptyline'></div>";
					jQ("#content-remind").append(html).show();
					jQ("#content-remind>div.line>a.ignore").click(remind_ignore);
					jQ("#content-remind>div.line>a.detail").click(remind_detail);
				}
			}
			
		}
	});
}
function removeLine(obj){
	jQ(obj).parent().fadeOut("slow",function(){
		jQ(this).remove();
		var content = jQ("#content-all");
		if(content.find("div.line").length<=0){
			content.append("<div class=\"line\"><span style=\"float: left; margin: 24px auto; font-size: 12px; padding-left: 20px;\">"+getNothingMsgText()+"</span></div>");
		}
	});
}
function getNothingMsgText(){
	var type = jQ("#message_tab li.onit").attr("mstype");
	return "暂无消息";
}
function request_ignore(){
	var requestuid=jQ(this).prevAll("span.request").attr("requestuid");
	var optobj=jQ(this);
	jQ.ajax({
		type : "POST",
		url : "contactAjax!responseContactRequest.action",
		data : {
			requestuid:requestuid,
			responsestatus : 0
		},
		success : function(data){
			if(data.result){
				optobj.parent().fadeOut("normal",function(){
					optobj.parent().remove();
					if(jQ("#content-request").find("div.line").length==0){
						var html="<span class='empty'>目前没有好友请求</span>";
						jQ("#content-request").empty().append(html).show();
					}
				});
			}else{
				alert(data.errormsg);
			}
		}
	});
}

function request_agree(){
	var requestuid=jQ(this).prevAll("span.request").attr("requestuid");
	var optobj=jQ(this);
	jQ.ajax({
		type : "POST",
		url : "contactAjax!responseContactRequest.action",
		data : {
			requestuid:requestuid,
			responsestatus : 1
		},
		success : function(data){
			if(data.result){
				optobj.parent().fadeOut("normal",function(){
					optobj.parent().remove();
					if(jQ("#content-request").find("div.line").length==0){
						var html="<span class='empty'>目前没有好友请求</span>";
						jQ("#content-request").empty().append(html).show();
					}
				});
			}else{
				alert(data.errormsg);
			}
		}
	});
}

function systemmsg_ignore(){
	var systemmsgid=jQ(this).prevAll("span.systemmsg").attr("systemmsgid");
	var optobj=jQ(this);
	jQ.ajax({
		type : "POST",
		url : "messageAjax!deleteSystemMessage.action",
		data : {
			systemmsgid:systemmsgid
		},
		success : function(data){
			if(data.result){
				optobj.parent().fadeOut("normal",function(){
					optobj.parent().remove();
					if(jQ("#content-systemmsg").find("div.line").length==0){
						var html="<span class='empty'>目前没有档期通知</span>";
						jQ("#content-systemmsg").append(html).show();
					}
				});
			}else{
				alert(data.errormsg);
			}
		}
	});
	
}

function systemmsg_detail(){
	var msgtype=eval(jQ(this).prevAll("span.systemmsg").attr("msgtype"));
	if(msgtype==2){
		var shareid=jQ(this).prevAll("span.systemmsg").attr("shareid");
		window.open(jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+shareid);
	}else{
		var eventid=jQ(this).prevAll("span.systemmsg").attr("eventid");
		window.open(jQ("#ctxVal").val()+"/myclip/recycle_detail.html?eventid="+eventid);
	}
}

function comment_ignore(){
	var noticeid=jQ(this).prevAll("span.comment").attr("noticeid");
	var optobj=jQ(this);
	jQ.ajax({
		type : "POST",
		url : "messageAjax!deleteMsgNotice.action",
		data : {
		noticeid:noticeid
		},
		success : function(data){
			if(data.result){
				optobj.parent().fadeOut("normal",function(){
					optobj.parent().remove();
					if(jQ("#content-comment").find("div.line").length==0){
						var html="<span class='empty'>目前没有评论提示</span>";
						jQ("#content-comment").append(html).show();
					}
				});
			}else{
				alert(data.errormsg);
			}
		}
	});
}

function comment_detail(){
	var shareid=jQ(this).prevAll("span.comment").attr("shareid");
	window.open(jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+shareid);
}

function remind_ignore(){
	var eventid=jQ(this).prevAll("span.remind").attr("eventid");
	var optobj=jQ(this);
	jQ.ajax({
		type : "POST",
		url : "eventAjax!cancelClock.action",
		data : {
		eventid:eventid
		},
		success : function(data){
			if(data.result){
				optobj.parent().fadeOut("normal",function(){
					optobj.parent().remove();
					if(jQ("#content-remind").find("div.line").length==0){
						var html="<span class='empty'>目前没有档期提醒</span>";
						jQ("#content-remind").append(html).show();
					}
				});
			}else{
				alert(data.msg);
			}
		}
	});
}

function remind_detail(){
	var eventid=jQ(this).prevAll("span.remind").attr("eventid");
	window.open(jQ("#ctxVal").val()+"/myclip/clip_detail.html?eventid="+eventid);
}

function initRightContent(){
	var type = null;
	type = getParameter("type");
	var var_usertype=eval(jQ("#var_usertype").val());
	if(var_usertype==2){
		jQ("#message_tab li[class~='comment']").siblings().hide();
		type="comment";
	}
	jQ("#message_tab li").mouseover(function(){
		if(jQ(this).hasClass("onit"))
			return false;
		else{
			var posStr=jQ(this).css("backgroundPosition");
			var posarr=posStr.split(" ");
			jQ(this).css("backgroundPosition",posarr[0] +" -22px");
		}
	});
	jQ("#message_tab li").mouseout(function(){
		if(jQ(this).hasClass("onit"))
			return false;
		else{
			var posStr=jQ(this).css("backgroundPosition");
			var posarr=posStr.split(" ");
			jQ(this).css("backgroundPosition",posarr[0] +"  0px");
		}
	});
	jQ("#message_tab li").click(function(){
		if(jQ(this).hasClass("onit"))
			return false;
		if(jQ("#message_tab li.onit").length>0){
			var posStr=jQ("#message_tab li.onit").css("backgroundPosition");
			var posarr=posStr.split(" ");
			jQ("#message_tab li.onit").css("backgroundPosition",posarr[0] +" 0px");
			jQ("#message_tab li.onit").removeClass("onit");
		}
		jQ(this).addClass("onit");
		var posStr=jQ(this).css("backgroundPosition");
		var posarr=posStr.split(" ");
		jQ(this).css("backgroundPosition",posarr[0] +"  -44px");
		jQ("#content-all").stop().hide();
		loadMessage(jQ(this).attr("mstype"));
	});
	if(type!=null&&jQ.trim(type).length>0){
		if(type=="systemmsg")
			type = 1;
		else if(type=="comment")
			type = 2;
		else if(type=="remind")
			type = 3;
		else
			type = 0;
	}else{
		type = 0;
	}
	jQ("#message_tab li").eq(type).click();
	
}